package com.naire.modul.sys_code.dao.impl;

import java.util.ArrayList;
import java.util.List;

import net.common.dao.GeneralDaoImpl;
import net.common.util.BeanUtils;

import com.naire.modul.sys_code.dao.Sys_codeDao;
import com.naire.modul.sys_code.pojo.Sys_code;
import com.naire.modul.sys_code.vo.Sys_codeVo;

public class Sys_codeDaoImpl extends GeneralDaoImpl implements Sys_codeDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Sys_codeVo> search() throws Exception {
		StringBuilder hql = new StringBuilder("from Sys_code");
		List<Sys_codeVo> d = new ArrayList<Sys_codeVo>();
		List<Sys_code> l = hibernateHandler.query(hql);
		for(Sys_code bean : l) {
			Sys_codeVo dv = new Sys_codeVo();
			BeanUtils.copyProperties(bean, dv);
			d.add(dv);
		}
		return d;
	}

	@Override
	public void insert(Sys_codeVo bean) throws Exception {
		Sys_code pojo = new Sys_code();
		BeanUtils.copyProperties(bean, pojo);
		hibernateHandler.insert(pojo);
	}

	@Override
	public void update(Sys_codeVo bean) throws Exception {
		Sys_code pojo = (Sys_code)hibernateHandler.find(Sys_code.class, bean.getSys_code_id());
		BeanUtils.copyProperties(bean, pojo);
		hibernateHandler.update(pojo);
	}

	@Override
	public void updateFlag(Sys_codeVo bean) throws Exception {
		update(bean);
	}

	@Override
	public Sys_codeVo find(Integer id) throws Exception {
		Sys_code pojo = (Sys_code)hibernateHandler.find(Sys_code.class, id);
		Sys_codeVo bean = new Sys_codeVo();
		BeanUtils.copyProperties(pojo, bean);
		return bean;
	}
}
